-- @Author: 作者QQ381990860
-- @Date:   2022-08-21 11:09:44
-- @Last Modified by:   作者QQ201878826
-- @Last Modified time: 2022-08-29 18:31:44
--======================================================================--
-- @作者: QQ381990860
-- @创建时间:   2019-12-03 02:17:19
-- @Last Modified time: 2021-12-16 16:32:42
--======================================================================--
local 场景类_魔兵宝箱 = class(窗口逻辑)
local tp,zts,zts1
local 图像类 = require("gge图像类")
local bwh = require("gge包围盒")
local bw = bwh(0,0,50,50)
local insert = table.insert
function 场景类_魔兵宝箱:初始化(根)
	self.ID = 3301223
	self.x = 300+(全局游戏宽度-800)/2
	self.y = 50
	self.xx = 0
	self.yy = 0
	self.注释 = "摇骰子"
	self.可视 = false
	self.鼠标 = false
	self.焦点 = false
	self.可移动 = false
	local 按钮 = 根._按钮
	local 自适应 = 根._自适应
	local 资源 = 根.资源
	self.人物头像背景 = {}
	self.资源组 = {
	[1] = 自适应.创建(0,1,220,387,3,9),
	[2] = 自适应.创建(3,1,40,19,1,3),
	[3] = 按钮.创建(自适应.创建(18,4,16,16,4,3),0,0,4,true,true),
	}
	

   self.资源组[3]:绑定窗口_(3301223)

	 self.骰子组={
	 [1] = 图像类(程序目录.."data/pic/骰子1.png"),
	 [2] = 图像类(程序目录.."data/pic/骰子2.png"),
	 [3] = 图像类(程序目录.."data/pic/骰子3.png"),
	 [4] = 图像类(程序目录.."data/pic/骰子4.png"),
	 [5] = 图像类(程序目录.."data/pic/骰子5.png"),
	 [6] = 图像类(程序目录.."data/pic/骰子6.png"),
	 }  
	
	--self.资源组2 = 图像类(程序目录.."data/pic/jdt1.png")

    self.停止= false
	self.窗口时间 = 0
	self.结果 = 0
	tp = 根
end

function 场景类_魔兵宝箱:刷新(数据)

        self.数据=数据
		self.结果 = tonumber(self.数据.点数)
		self.中奖结果 = self.数据.中奖
		self.中奖结果1 = {"抽奖兑换券","星辉石1—3J礼包","星辉石2—6J礼包","宝石1—5J礼包","宝石5—8J礼包","星辉石6—9J礼包","五宝礼盒","三界密录"}
		
		local item =ItemData[self.中奖结果]
		self.资源组1 = {}
		for n = 1, 5 do
		
		  if (self.结果 <= 20 and  n ==1) or (self.结果 <= 40 and  n ==2) or (self.结果 <= 60 and  n ==3) or (self.结果 <= 80 and  n ==4) or (self.结果 <= 100 and  n ==5) then
		    self.资源组1[n] = tp.资源:载入(item.文件 ,"网易WDF动画",item.小图标)
		     else 
			 local item2 =ItemData[self.中奖结果1[math.random(#self.中奖结果1)]]
			 self.资源组1[n] = tp.资源:载入(item.文件 ,"网易WDF动画",item.小图标)
		  end
		end

end


function 场景类_魔兵宝箱:打开(数据)
	if self.可视 then
		self.可视 = false
		self.点击 = false

	else
		if  self.x > 全局游戏宽度 then
		   		self.x = 150+(全局游戏宽度-800)/2
		end
		
		self.数据=数据
		self.结果 = tonumber(self.数据.点数)
		self.中奖结果 = self.数据.中奖
		self.中奖结果1 = {"抽奖兑换券","星辉石1—3J礼包","星辉石2—6J礼包","宝石1—5J礼包","宝石5—8J礼包","星辉石6—9J礼包","五宝礼盒","三界密录"}
		
		local item =ItemData[self.中奖结果]

		self.资源组1 = {}
		for n = 1, 5 do
		
		  if (self.结果 <= 20 and  n ==1) or (self.结果 <= 40 and  n ==2) or (self.结果 <= 60 and  n ==3) or (self.结果 <= 80 and  n ==4) or (self.结果 <= 100 and  n ==5) then
		    self.资源组1[n] = tp.资源:载入(item.文件 ,"网易WDF动画",item.小图标)
		     else 
			 local item2 =ItemData[self.中奖结果1]
			 self.资源组1[n] = tp.资源:载入(item.文件 ,"网易WDF动画",item.小图标)
		  end
		end
		

		insert(tp.窗口_,self)
	    tp.运行时间 = tp.运行时间 + 1
	  	self.窗口时间 = tp.运行时间
	    self.可视 = true
		self.点击 = false

      self.停止= false
	  local s = ModelData[tp.场景.人物.数据.造型]
	  self.人物头像背景[1] = tp.资源:载入(s.头像资源,"网易WDF动画",s.中头像)
	end
end



function 场景类_魔兵宝箱:显示(dt,x,y)
	self.焦点 = false
      self.资源组[3]:更新(x,y)
      self.资源组[1]:显示(self.x,self.y)
	  self.资源组[2]:显示(self.x+88,self.y+55)
	  self.资源组[3]:显示(self.x+195,self.y+4)
	  tp.人物头像背景_:显示(self.x+20,self.y+30)
      self.人物头像背景[1]:显示(self.x+23,self.y+33)
	  tp.字体表.普通字体:置颜色(0xFFFFFFFF):显示(self.x+80,self.y+30,"我的点数")
	 
 tp.字体表.普通字体:置颜色(0xFFFFFFFF):显示(self.x+110,self.y+100,"1~20点")
 tp.字体表.普通字体:置颜色(0xFFFFFFFF):显示(self.x+110,self.y+100+60,"21~40点")
 tp.字体表.普通字体:置颜色(0xFFFFFFFF):显示(self.x+110,self.y+100+120,"41~60点")
 tp.字体表.普通字体:置颜色(0xFFFFFFFF):显示(self.x+110,self.y+100+180,"61~80点")
 tp.字体表.普通字体:置颜色(0xFFFFFFFF):显示(self.x+110,self.y+100+240,"81~100点") 
 
	  self.资源组1[1]:显示(self.x+45,self.y+85)
	  self.资源组1[2]:显示(self.x+45,self.y+85+60)
	  self.资源组1[3]:显示(self.x+45,self.y+85+120)
	  self.资源组1[4]:显示(self.x+45,self.y+85+180)
      self.资源组1[5]:显示(self.x+45,self.y+85+240)  

	  
	  if self.停止== false then
      self.骰子组[math.random(6)]:显示(self.x+153,self.y+31)
	  bw:置坐标(self.x+153,self.y+31)
	  else 
	  
	  
	  
	  if self.结果 <= 10  then 
	  self.骰子组[1]:显示(self.x+153,self.y+31)
	  tp.技能认证:显示(self.x+50,self.y+90)
	  
	  elseif  self.结果 <= 20  then 
	  self.骰子组[2]:显示(self.x+153,self.y+31)
	  tp.技能认证:显示(self.x+50,self.y+90)
	  
	  elseif  self.结果 <= 40  then 
	  self.骰子组[3]:显示(self.x+153,self.y+31)
	  tp.技能认证:显示(self.x+50,self.y+90+60)
	  
	  elseif  self.结果 <= 60  then 
	  self.骰子组[4]:显示(self.x+153,self.y+31)
	 tp.技能认证:显示(self.x+50,self.y+90+120)
	  
	  elseif  self.结果 <= 80  then 
	  self.骰子组[5]:显示(self.x+153,self.y+31)
	  tp.技能认证:显示(self.x+50,self.y+90+180)
	  
	  elseif  self.结果 <= 100  then 
	  self.骰子组[6]:显示(self.x+153,self.y+31)
	  tp.技能认证:显示(self.x+50,self.y+90+240)
	  
	  end
	  
	  tp.字体表.普通字体:置颜色(0xFF000000):显示(self.x+100,self.y+60,self.结果)
	  end

	  if self.鼠标 and not tp.消息栏焦点 and bw:检查点(x,y) and 引擎.鼠标弹起(0) and self.停止== false then
	     self.停止 = true
	     客户端:发送数据(2, 292, 13, self.数据.中奖, 1)
		
	   
	  end
end




return 场景类_魔兵宝箱